const fs = require('fs')

let mkdirSingle = function(dirname) {
    fs.stat(dirname, function(err, stats) {
        if (err) {
            if (err.code == "ENOENT") { //如果不是一个目录，创建
                fs.mkdir(dirname, (err) => {})
            } else {
                throw err
            }
        }
    })
}
let mkdir = function(dirname) {
    let arr = dirname.split('/').filter(function(e) {
        return e != ''
    });
    mkdirSingle(arr[0])
    if (arr != undefined) {
        for (let i = 1; i < arr.length; i++) { //whan arr>1 
            let name = arr.slice(0, i + 1).join('/')
            setTimeout(() => mkdirSingle(name), 50 * i)
        }
    }
}

// let deldirSingle = function(dirname) {
//     fs.stat(dirname, function(err, stats) {
//         if (err) {
//             if (err.code == "ENOENT") { //如果不是一个目录，创建
//                 fs.mkdir(dirname, (err) => {})
//             } else {
//                 throw err
//             }
//         }
//     })
// }
// let deldir = function(dirname) {
//     let arr = dirname.split('/').filter(function(e) {
//         return e != ''
//     });
//     deldirSingle(arr[0])
//     if (arr != undefined) {
//         for (let i = 1; i < arr.length; i++) { //whan arr>1 
//             let name = arr.slice(0, i + 1).join('/')
//             setTimeout(() => deldirSingle(name), 50 * i)
//         }
//     }
// }

function test() {
    mkdir('aaa/bbb/ccc/')
}
// test()

exports.mkdir = mkdir;
// exports.deldir = deldir;